package info.rongtong.utils;

import info.rongtong.service.inter.CategoryServiceInter;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.WebApplicationContext;

public class LoadListener implements ServletContextListener {
	private CategoryServiceInter categoryServiceImpl;
	private Thread t=null;
	public void contextDestroyed(ServletContextEvent arg0) {
		t.stop();
	}

	public void contextInitialized(ServletContextEvent arg0) {
		//查询类别
		ApplicationContext app =  (ApplicationContext) arg0.getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
		categoryServiceImpl = (CategoryServiceInter) app.getBean("categoryServiceImpl");
		List list= categoryServiceImpl.getCategoryByType(0);
		arg0.getServletContext().setAttribute("categoryInfoList", list);
		app = null;
		//启动检查是否更新线程
		 t= new Thread(new CheckAndUpdateContextThread(arg0.getServletContext()));
		t.start();
	}

	

	
}
